$('.right-titleicon').on("click", function(e) {
	projectVM.showMenulist()
})
  
projectVM = new Vue({
	el: "#content",
	data: {
		stationList:[],
		editIndex:'', 
		form1:{},  //主变器1号 详细信息
		form2:{},
		form3:{},
		form4:{},
		showEditform:false,
		nowDate:'',
		zbq1:[],  //主变器1号
		zbq2:[],
		zbq3:[],
		zbq4:[],
		hv:'',
		byq:[],
		list:[],
		workId:'',
		currentUser:'',
		showAddform:false,
		editForm:[],
		zbq1_10:'',
		zbq1_35:'',
		zbq2_10:'',
		zbq2_35:'',
		zbq3_10:'',
		zbq3_35:'',
		zbq4_10:'',
		zbq4_35:'',
	},
	components: {
		personselect,
		processlog
	},
	created() {
		this.workId = JSON.parse(localStorage.getItem('todoWork')).obj.workId
		this.currentUser = JSON.parse(localStorage.getItem('neiosUser'))
		this.getNowdate()
		this.getStationCode()
		
	}, 
	methods: {
		//选择场站
			showStationList(index){
				var that = this
				 let picker = new mui.PopPicker({
					 layer:1
				 })
				 picker.setData(this.stationList)
				  picker.show(function(e) {   //e 就是总数据的数组 显示picker
					that.list[index].templateCode = e[0].value
					that.list[index].templateName = e[0].text
				})
			
			},
		clearaddForm(){
		this.showAddform = false	
		this.hv = ''
		this.byq = []
		this.zbq1=[],  //主变器1号
		this.zbq2=[],
		this.zbq3=[],
		this.zbq4=[],
		this.zbq1_10='',
		this.zbq1_35='',
		this.zbq2_10='',
		this.zbq2_35='',
		this.zbq3_10='',
		this.zbq3_35='',
		this.zbq4_10='',
		this.zbq4_35=''
		},
		//获取场站列表
		getStationCode(){
			var that = this
			var param = {
				orgType:'2',
				parentOrgCode:this.currentUser.companyNewCode,
				parentOrgType:'1'	
			}							 
			mui.neiosRequst.httpRequst('/common/organization/getOrganizationListByType', param,
				(data)=> {
				if(data.code ==  0){	
					let arr = []
					data.data.forEach(item=>{
						if(item.newOrgName != '' && item.newOrgName != null){
							arr.push({
								text:item.newOrgName,
								value:item.newOrgCode
							})
						}
						
					})
					that.stationList = arr
					
					that.getList()
				}
				else{
					mui.toast(data.msg)
				}
			
				},
				function(data) {
				
				})
		},
		showAdd(){
			this.showAddform = true;
		},
		//确认
		confirm(){
			
			if(!this.editForm.av || !this.editForm.aa || !this.editForm.bv || !this.editForm.ba || !this.editForm.cv || !this.editForm.ca){
				mui.toast('请输入高压侧信息')
				return
			}
			var able = true
			var info = this.editForm.neiosBoosterTran
			info.forEach(item=>{
				if(!item.windingC || !item.upC || !item.downC || !item.powerLoad){
					able = false
				}
				item.neiosBoosterLine.forEach(item1=>{
					if(!item1.lineV || !item1.lineA){
						able = false
					}
				})
			})
			if(!able){
				mui.toast('请输入变压器信息')
				return
			}
			this.showEditform = false
		},
		//编辑
		edit(e,f){
			
			this.editForm = e
			this.editIndex = f
			this.showEditform = true
		},
		//添加设备
		addList(){
		 if(this.hv == ''){
			 mui.toast('请选择高压值')
			 return
		 }
		 else if(this.byq.length == 0){
			 mui.toast('请选择主变器')
			 return
		 }
		 else if(this.byq.length == 0){
		 		mui.toast('请选择主变器')
		 		return
		 }
		else if(this.byq.indexOf('1') >=0){
			 if(this.zbq1 == ''){
				 mui.toast('请选择1号高压侧电压值')
				 return
			 }
			 else if(this.zbq1.indexOf('10kv') >=0){
				 if(this.zbq1_10 == ''){
					 mui.toast('请输入母线段数')
					 return
				 }
			 }
			 else if(this.zbq1.indexOf('35kv') >=0){
			 				 if(this.zbq1_35 == ''){
			 					 mui.toast('请输入母线段数')
			 					 return
			 				 }
			 }
			 
		 }
		  if(this.byq.indexOf('2') >=0){
		 	 if(this.zbq2 == ''){
		 		 mui.toast('请选择2号高压侧电压值')
		 		 return
		 	 }
		 	 else if(this.zbq2.indexOf('10kv') >=0){
		 		 if(this.zbq2_10 == ''){
		 			 mui.toast('请输入母线段数')
		 			 return
		 		 }
		 	 }
			 else if(this.zbq2.indexOf('35kv') >=0){
			 		 		 if(this.zbq2_35 == ''){
			 		 			 mui.toast('请输入母线段数')
			 		 			 return
			 		 		 }
			 }
		  }
		   if(this.byq.indexOf('3') >=0){
		  	 if(this.zbq3 == ''){
		  		 mui.toast('请选择3号高压侧电压值')
		  		 return
		  	 }
		  	 else if(this.zbq3.indexOf('10kv') >=0){
		  		 if(this.zbq3_10 == ''){
		  			 mui.toast('请输入母线段数')
		  			 return
		  		 }
		  	 }
		  	 else if(this.zbq3.indexOf('35kv') >=0){
		  	 				 if(this.zbq3_35 == ''){
		  	 					 mui.toast('请输入母线段数')
		  	 					 return
		  	 				 }
		  	 }
		   }
		    if(this.byq.indexOf('4') >=0){
		   	 if(this.zbq4 == ''){
		   		 mui.toast('请选择4号高压侧电压值')
		   		 return
		   	 }
		   	 else if(this.zbq4.indexOf('10kv') >=0){
		   		 if(this.zbq4_10 == ''){
		   			 mui.toast('请输入母线段数')
		   			 return
		   		 }
		   	 }
		   	 else if(this.zbq4.indexOf('35kv') >=0){
		   	 				 if(this.zbq4_35 == ''){
		   	 					 mui.toast('请输入母线段数')
		   	 					 return
		   	 				 }
		   	 }
		    }
			var neiosBoosterTran = [{},{},{},{}]
			
			var list =JSON.stringify(this.byq.join(',')) 
			list = list.replace('"','').replace('"',"")
			list = list.split(',')
			console.log(typeof(this.byq),this.byq)
			if(list == this.byq){
				var arr = []
				var lv = ''
				arr[0] = this.byq
				list = arr
			}
			
			list.forEach((item,index)=>{
				if(item ==1){
					let neiosBoosterLine = []
					lv = this.zbq1
					if(this.zbq1_10 != ''){
						for(let i=0;i<this.zbq1_10;i++){		
	 						let obj =  {
									  "sort":item,
									  "lv":'10kv',
									  "lineV":"",
									  "lineA":"",
									  "remark":""
									}
									neiosBoosterLine.push(obj)
						}
					}
					if(this.zbq1_35 != ''){
						for(let i=0;i<this.zbq1_35;i++){
							let obj =  {
									  "sort":item,
									  "lv":'35kv',
									  "lineV":"",
									  "lineA":"",
									  "remark":""
									}
									neiosBoosterLine.push(obj)
						}
					}
					let obj ={
						neiosBoosterLine:neiosBoosterLine,
						downC:'',
						lv:lv,
						powerLoad:'',
						remark:'',
						sort:item,
						upC:'',
						windingC:''
					}
					console.log(item,obj)
					neiosBoosterTran[item-1] = obj
				}
				if(item ==2){
					let neiosBoosterLine = []
					lv = this.zbq2
					if(this.zbq2_10 != ''){
						for(let i=0;i<this.zbq2_10;i++){
							let obj =  {
									  "sort":item,
									  "lv":'10kv',
									  "lineV":"",
									  "lineA":"",
									  "remark":""
									}
									neiosBoosterLine.push(obj)
						}
					}
					if(this.zbq2_35 != ''){
						for(let i=0;i<this.zbq2_35;i++){
							let obj =  {
									  "sort":item,
									  "lv":'35kv',
									  "lineV":"",
									  "lineA":"",
									  "remark":""
									}
									neiosBoosterLine.push(obj)
						}
				}
				let obj ={
					neiosBoosterLine:neiosBoosterLine,
					downC:'',
					lv:lv,
					powerLoad:'',
					remark:'',
					sort:item,
					upC:'',
					windingC:''
				}
				console.log(item,obj)
				neiosBoosterTran[item-1] = obj
				}

				if(item ==3){
					let neiosBoosterLine = []
					lv = this.zbq3
					if(this.zbq3_10 != ''){
						for(let i=0;i<this.zbq3_10;i++){
							let obj =  {
									  "sort":item,
									  "lv":'10kv',
									  "lineV":"",
									  "lineA":"",
									  "remark":""
									}
									neiosBoosterLine.push(obj)
						}
					}
					if(this.zbq3_35 != ''){
						for(let i=0;i<this.zbq3_35;i++){
							let obj =  {
									  "sort":item,
									  "lv":'35kv',
									  "lineV":"",
									  "lineA":"",
									  "remark":""
									}
									neiosBoosterLine.push(obj)
						}
				}
				let obj ={
					neiosBoosterLine:neiosBoosterLine,
					downC:'',
					lv:lv,
					powerLoad:'',
					remark:'',
					sort:item,
					upC:'',
					windingC:''
				}
				console.log(item,obj)
				neiosBoosterTran[item-1] = obj
				}
				if(item ==4){
					let neiosBoosterLine = []
					lv = this.zbq4
					if(this.zbq4_10 != ''){
						for(let i=0;i<this.zbq4_10;i++){
							let obj =  {
									  "sort":item,
									  "lv":'10kv',
									  "lineV":"",
									  "lineA":"",
									  "remark":""
									}
									neiosBoosterLine.push(obj)
						}
					}
					if(this.zbq4_35 != ''){
						for(let i=0;i<this.zbq4_35;i++){
							let obj =  {
									  "sort":item,
									  "lv":'35kv',
									  "lineV":"",
									  "lineA":"",
									  "remark":""
									}
									neiosBoosterLine.push(obj)
						}
				}
				let obj ={
					neiosBoosterLine:neiosBoosterLine,
					downC:'',
					lv:lv,
					powerLoad:'',
					remark:'',
					sort:item,
					upC:'',
					windingC:''
				}
				console.log(item,obj)
				neiosBoosterTran[item-1] = obj
			}
			})
			console.log(JSON.stringify(neiosBoosterTran))
			
		 var info ={
			 edit:true,
			 templateName:'',
			 aa:'',
			 av:'',
			 ba:'',
			 bv:'',
			 ca:'',
			 cv:'',
			 hv:this.hv,
			 rules:{
			 				  highValue:this.hv,
			 				  busBar1_10:this.toArr(this.zbq1_10),
			 				  busBar2_10:this.toArr(this.zbq2_10),
			 				  busBar3_10:this.toArr(this.zbq3_10),
			 				  busBar4_10:this.toArr(this.zbq4_10),
			 				  busBar1_35:this.toArr(this.zbq1_35),
			 				  busBar2_35:this.toArr(this.zbq2_35),
			 				  busBar3_35:this.toArr(this.zbq3_35),
			 				  busBar4_35:this.toArr(this.zbq4_35),
			 				  mainValue:this.byq.join(','),
			 				  mainValue1:this.zbq1.join(','),
			 				  mainValue2:this.zbq2.join(','),
			 				  mainValue3:this.zbq3.join(','),
			 				  mainValue4:this.zbq4.join(','),
			 },
			 neiosBoosterTran:neiosBoosterTran
		 }
		 console.log(JSON.stringify(info))
		 this.list.push(info)
		 this.showAddform = false	
		 this.clearaddForm()
		},
		//转数组
		toArr(e){
			
			if(e == ''){
				return []
			}
			var arr = []
			for(let i=1;i<=e;i++){
				arr.push(i)
			}
			return arr
		},
		//清除表单
		clearForm(){
				this.byq = []
				this.zbq1 = []
				this.zbq2 = []
				this.zbq3 = []
				this.zbq4 = []
		},
		//获取当前时间
		getNowdate() {
			var date = new Date()
			var year = date.getFullYear()
			var month = date.getMonth()
			var day = date.getDate()
			month = month*1 + 1
			if (month.toString().length < 2) {
				month = '0' + month
			}
			if (day.toString().length < 2) {
				day = '0' + day
			}
			this.nowDate = year + '-' + month + '-' + day
		},
		//添加模块
		add(){
			var info = {
				edit:true,
				templeteName:'',
			}
			this.list.push(info)
		},
		//保存提交
		save(e){
			if(this.list.length == 0){
				mui.toast('请添加升压站')
				return
			}
			var that = this
			var able = true
			
			if(e == 2){
				
				this.list.forEach(item=>{
					if(item.templateName == ''){
						mui.toast('请选择升压站')
						able = false
					}
					else if(item.aa == ''){
						 mui.toast('请填写完整信息')
						able = false
					}
				})
			}
			if(!able){
				return
			}
		var param = {
			workType:'0405',
			bizTypeId:'RSP',
			checkCode:this.currentUser.userId,
			checkDate:this.nowDate,
			checkName:this.currentUser.name,
			newAreaCode:this.currentUser.companyNewCode,
			remark:'',
			submitType:e,
			workId:this.workId,
			neiosBooster:this.list
		}
		console.log(JSON.stringify(param))
		
		mui.neiosRequst.httpRequst('/app/booster/create', param,
						(data)=> {
						if(data.code ==  0){
							if( e == 1){
								mui.toast("保存成功")
								setTimeout(function() {
									location.reload();
								}, 1000);
							}
							else{
								mui.toast("操作成功")
								setTimeout(function() {
								that.goBack()
								}, 1000);
							}
							
						}
						else{
							mui.toast(data.msg)
						}
		
						},
						function(data) {
		
						})
		},

		//删除
		delItem(index){
			let btnArray = ['取消', '确定'];
			mui.confirm('是否确认删除?', '提示', btnArray, (e)=> {
				if (e.index == 1) {
					this.list.splice(index,1)
				}
				else{}
			})
			
		},
		//获取默认数据
		getAreaData(){
			var param = {
				bizTypeId:"RSP",
				newAreaCode:this.currentUser.companyNewCode
			}
			mui.neiosRequst.httpRequst('/app/booster/queryByAreaCode', param,
							(data)=> {
								
							this.list = data.data[0].neiosBooster 
							},
							function(data) {
							console.log(JSON.stringify(param))
							})
		},
		//获取功能模板列表
		getList(){
			var param = {
				bizTypeId:'RSP',
				workId:this.workId
			}
			console.log(JSON.stringify(param))
			mui.neiosRequst.httpRequst('/app/booster/query', param,
							(data)=> {
				
							if(data.data.length !=  0){
								 this.list = data.data[0].neiosBooster 
								 this.list.forEach(item=>{
									 this.stationList.forEach(item1=>{
										 
										 if(item.templateCode == item1.value){
											 
											 item.templateName = item1.text
										 }
									 })
								 })
								 
							}
							else{
								this.getAreaData()
							}

							},
							function(data) {

							})
		},
		//返回
		goBack(){
			let page2 = plus.webview.getWebviewById("../sitOperation/terminalwork/terminalwork.html");
			let param = {}
			param.isRefresh = true
			mui.fire(page2, 'isRefresh', param);
			mui.back()
		},
	}

})
